***************** Replication of Franchino, Fabio, and Camilla Mariotto. “Bargaining Outcomes and Success in EU Economic Governance Reforms”. Political Science Research and Methods.

* Step 1 to reproduce Figure 2

version 16

******************************* SENSITIVITY ANALYSIS  - Add Gaussian random noise to positions
*************   COMPUTING POINT PREDICTIONS: PROC - Procedural model solutions with reference point
clear all
set obs 1
gen v = _n/10
save mad_PROCrp_noise.dta, replace

set seed 1234

local m =  1  /* iteration per each s.d. value */
while `m' <= 1000 {

local v = 0.1  /* v is s.d of Gaussian noise - s.d. of country and institutional positions is 41.74882 */
while `v' <= 42.1 {
* Upload original dataset
use PROCmodel_data.dta, clear

* Add Gaussian noise N(0,v) to Commission positions
generate random = rnormal(0,`v') if country==1 /* one random noise per issue */
bysort issue_id: egen random_max = max(random)
drop random
rename random_max random
replace comm=comm+random 
replace comm=100 if comm>100 
replace comm=0   if comm<0 

* Add Gaussian noise N(0,v) to Parliament positions
replace random = rnormal(0,`v') if country==1 /* one random noise per issue */
bysort issue_id: egen random_max = max(random)
drop random
rename random_max random
replace ep_1=ep_1+random
replace ep_1=100 if ep_1>100 
replace ep_1=0   if ep_1<0 

* Add Gaussian noise N(0,v) to country positions
replace random = rnormal(0,`v')
replace cntry_pos=cntry_pos+random
replace cntry_pos=100 if cntry_pos>100 
replace cntry_pos=0   if cntry_pos<0 

* Compute PROC equilibrium outcomes and absolute differences between outcomes and model predictions
do PROCrp_step1.do

* Compute means of absolute differences between outcomes and model predictions
gen v = `v'
rename mad mad`m'
collapse v mad`m'
label variable mad`m' "mean of absolute differences" 
label variable v "s.d of Gaussian noise" 

merge 1:1 v using mad_PROCrp_noise.dta, nogen
save mad_PROCrp_noise.dta, replace
sort v
pause 1000

       
local v = `v' + 1 /* increments of s.d. */
}

local m = `m' + 1 /* simulations */
}

egen PROCrp = rowmean(mad*)
label variable PROCrp "mean of absolute differences across m simulations" 
egen PROCrp_u = rowpctile(mad*), p(97.5)
label variable PROCrp_u "upper boundary" 
egen PROCrp_l = rowpctile(mad*), p(2.5)
label variable PROCrp_l "lower boundary" 

drop mad*
save mad_PROCrp_noise.dta, replace

exit

